/**
 @file ctc_dtel.h

 @author  Copyright (C) 2011 Centec Networks Inc.  All rights reserved.

 @date 2018-11-26

 @version v2.0

   This file contains all L2 related data structure, enum, macro and proto.
*/

#ifndef _CTC_DTEL_H
#define _CTC_DTEL_H
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "common/include/ctc_const.h"

/****************************************************************
*
* Defines and Macros
*
****************************************************************/

/**
 @defgroup dtel DTEL
 @{
*/

#define CTC_DTEL_INT_SINK_SESSION_NUM  32
#define CTC_DTEL_IFA_SESSION_NUM  32
#define CTC_DTEL_IFA_GNS_NUM  16
#define CTC_DTEL_IFA_REQ_VEC_BIT_NUM 8 

/**
 @brief  define INT probe marker
*/
typedef uint32  ctc_int_probe_marker_t[2];

/**
 @brief  define INT Session type
*/
enum ctc_dtel_int_session_type_e
{
  CTC_DTEL_INT_SESSION_TYPE_NONE,           /**< [TMM.AT] Keep Session Type*/
  CTC_DTEL_INT_SESSION_TYPE_CANCEL,         /**< [TMM.AT] Cancel Session Type */
  CTC_DTEL_INT_SESSION_TYPE_SOURCE,         /**< [TMM.AT] Source node*/
  CTC_DTEL_INT_SESSION_TYPE_TRANSMIT,       /**< [TMM.AT] Transmit node*/
  CTC_DTEL_INT_SESSION_TYPE_SINK,           /**< [TMM.AT] Sink node*/
  CTC_DTEL_INT_SESSION_TYPE_SOURCE_TRANSMIT /**< [TMM.AT] Source or Transmit node*/
};
typedef enum ctc_dtel_int_session_type_e ctc_dtel_int_session_type_t;
/**
 @brief  define INT Instruction bitmap
*/

enum ctc_dtel_int_ins_bitmap_e
{
    CTC_DTEL_INT_INS_SW_ID       = 0x01, /**< [TMM.AT] Switch ID*/
    CTC_DTEL_INT_INS_LV1_PORT    = 0x02, /**< [TMM.AT] Level 1 Ingress port ID +  Egress port ID*/
    CTC_DTEL_INT_INS_HOP_LATENCY = 0x04, /**< [TMM.AT] Hop latency*/
    CTC_DTEL_INT_INS_QUEUE_INFO  = 0x08, /**< [TMM.AT] Queue id + Queue occupancy*/
    CTC_DTEL_INT_INS_IGS_TS      = 0x10, /**< [TMM.AT] Ingress timestamp*/
    CTC_DTEL_INT_INS_EGS_TS      = 0x20, /**< [TMM.AT] Egress timestamp*/
    CTC_DTEL_INT_INS_LV2_PORT    = 0x40, /**< [TMM.AT] Level 2 Ingress port ID +  Egress port ID*/
    CTC_DTEL_INT_INS_EPTU        = 0x80  /**< [TMM.AT] Egress port Tx utilization*/
};
typedef enum ctc_dtel_int_ins_bitmap_e ctc_dtel_int_ins_bitmap_t;


enum ctc_dtel_int_lv2_port_mode_e
{
    CTC_DTEL_INT_LV2_PORT_MODE_GPORT ,      /**< [TMM.AT] Global source port  + Global dest port*/
    CTC_DTEL_INT_LV2_PORT_MODE_LOGIC_PORT , /**< [TMM.AT] Logic source port  + Logic dest port*/
    CTC_DTEL_INT_LV2_PORT_MODE_INTERFACE,   /**< [TMM.AT] L3 Src interface & Dest interface*/
};
typedef enum ctc_dtel_int_lv2_port_mode_e ctc_dtel_int_lv2_port_mode_t;

struct ctc_dtel_int_transmit_action_s
{
  uint8 session_type;       /**< [TMM.AT] Valid type :NONE/CANCEL/SINK, refer to ctc_dtel_int_session_type_t */
  uint8 session_id;         /**< [TMM.AT] Session ID */
  uint8 action;             /**< [TMM.AT] Action, refer to ctc_exception_type_t*/
};
typedef struct ctc_dtel_int_transmit_action_s ctc_dtel_int_transmit_action_t;


enum ctc_dtel_ifa_request_vector_e
{
    CTC_DTEL_IFA_REQ_VEC_LV1_PORT    = 0x01, /**< [TMM.AT] Level 1 Ingress port ID +  Egress port ID*/
    CTC_DTEL_IFA_REQ_VEC_HOP_LATENCY = 0x02, /**< [TMM.AT] Hop latency*/
    CTC_DTEL_IFA_REQ_VEC_QUEUE_INFO  = 0x04, /**< [TMM.AT] Queue id + Queue occupancy*/
    CTC_DTEL_IFA_REQ_VEC_IGS_TS      = 0x08, /**< [TMM.AT] Ingress timestamp*/
    CTC_DTEL_IFA_REQ_VEC_EGS_TS      = 0x10, /**< [TMM.AT] Egress timestamp*/
    CTC_DTEL_IFA_REQ_VEC_EPTU        = 0x20, /**< [TMM.AT] Egress port Tx utilization*/
    CTC_DTEL_IFA_REQ_VEC_LV2_PORT    = 0x40  /**< [AT] Level 2 Ingress port ID Egress port ID*/
};
typedef enum ctc_dtel_ifa_request_vector_e ctc_dtel_ifa_request_vector_t;

enum ctc_dtel_ifa_node_e
{
    CTC_DTEL_IFA_NODE_NONE,             /**< [TMM.AT] None Operation Node */
    CTC_DTEL_IFA_NODE_INITIATOR,        /**< [TMM.AT] Initiator Node*/
    CTC_DTEL_IFA_NODE_TRANSIT,          /**< [TMM.AT] Transit Node*/
    CTC_DTEL_IFA_NODE_TERMINATE,        /**< [TMM.AT] Terminating Node*/
    CTC_DTEL_IFA_NODE_MAX
};
typedef enum ctc_dtel_ifa_node_e ctc_dtel_ifa_node_t;

struct ctc_dtel_ifa_cfg_s
{
    uint8 session_id;   /**< [TMM.AT] IFA session ID*/
    uint8 node;         /**< [TMM.AT] IFA node type*/

    uint8 log_percent;  /**< [TMM.AT] Initiator Node. IFA initiator flow log percent, refer to ctc_log_percent_t*/
    uint8 gns;          /**< [TMM.AT] Initiator Node. Global name space for IFA header*/
    uint8 max_length;   /**< [TMM.AT] Initiator Node. Max length for IFA header*/
    uint8 hop_limit;    /**< [TMM.AT] Initiator Node. Hop limit for IFA header*/
    uint8 req_vec;      /**< [TMM.AT] Initiator Node. Request vector for IFA metadata header, refer to ctc_dtel_ifa_request_vector_t*/

    uint32 nh_id;       /**< [TMM.AT] Terminate Node. IFA terminate node report destination, if nh_id == 0, means report to user by packet rx callback*/
};
typedef struct ctc_dtel_ifa_cfg_s ctc_dtel_ifa_cfg_t;


struct ctc_dtel_ifa_mode_cfg_s
{
    uint8 version;    /**< [AT] IFA version select. Defalut 0:IFA 2.0, 1:IFA 1.0, 2:IFA 2.0 */
    uint8 req_vec[CTC_DTEL_IFA_REQ_VEC_BIT_NUM];    /**< [AT] IFA request vector bits specified by user, refer to ctc_dtel_ifa_request_vector_t */
};
typedef struct ctc_dtel_ifa_mode_cfg_s ctc_dtel_ifa_mode_cfg_t;



enum ctc_dtel_int_mode_e
{
    CTC_DTEL_INT_MODE_DSCP,           /**< [TMM.AT] INT mode based on DSCP */
    CTC_DTEL_INT_MODE_PROBE_MARKER,   /**< [TMM.AT] INT mode based on probe marker */
    CTC_DTEL_INT_MODE_MAX
};
typedef enum ctc_dtel_int_mode_e ctc_dtel_int_mode_t;


struct ctc_dtel_int_mode_cfg_s
{
    uint32 mode;                            /**< [TMM.AT] Refer to ctc_dtel_int_mode_t*/
    ctc_int_probe_marker_t probe_marker;    /**< [TMM.AT] Probe marker value, if set 0, means not use probe_marker value,
                                                       valid when mode == CTC_DTEL_INT_MODE_PROBE_MARKER */
    uint16 l4_dest_port;                    /**< [TMM.AT] TCP/UDP destination port, if set 0, means not use l4_dest_port value,
                                                       valid when mode == CTC_DTEL_INT_MODE_PROBE_MARKER */
    uint16 dscp;                            /**< [TMM.AT] If bit 15 set，indicate dscp value to int, else, one bit to int */
    uint8 l4_chksum_mode;                    /**< [TMM.AT] L4 checksum update mode, 0 means to set l4chksum to 0, 1 means not to update l4chksum, 2 means to update l4chksum */
};
typedef struct ctc_dtel_int_mode_cfg_s ctc_dtel_int_mode_cfg_t;


enum ctc_dtel_property_e
{
     CTC_DTEL_INT_EN,                           /**< [TMM.AT] Enable INT */
     CTC_DTEL_INT_TS_GRAN,                      /**< [TMM.AT] Timestamp granularity(s bits, ns bits), 0:(2,30), 1:(5,27), 2:(8,24), 3:(11,21) */
     CTC_DTEL_INT_REP_LEN_THRD,                 /**< [TMM.AT] INT Header length for report */
     CTC_DTEL_INT_SINK_LEN_THRD,                /**< [TMM.AT] INT Header length for sink */
     CTC_DTEL_INT_REMAINING_HOP_THRD,           /**< [TMM.AT] Remaining hop threshold */
     CTC_DTEL_INT_REMAINING_HOP_CNT,            /**< [TMM.AT] Remaining hop count, range <1-0xFF> */
     CTC_DTEL_INT_LV2_PORT_MODE,                /**< [TMM.AT] Level 2 port mode, refer to ctc_dtel_int_lv2_port_mode_t */

     /*the following cfg only occur on transmit node,the configured data is ctc_dtel_int_transmit_action_t*/
     CTC_DTEL_INT_CBIT_NOT_EQ_ZERO_ACTION,      /**< [TMM.AT] C bit !=0 ,the  default action is CTC_DTEL_INT_TRANSIT_ACTION_REDIRECT_TO_CPU */
     CTC_DTEL_INT_REP_NOT_EQ_ZERO_ACTION,       /**< [TMM.AT] Rep bits !=0 ,the default action  is CTC_DTEL_INT_TRANSIT_ACTION_REDIRECT_TO_CPU*/
     CTC_DTEL_INT_EXCEED_SINK_LEN_ACTION,       /**< [TMM.AT] The INT Header's length exceed  CTC_DTEL_INT_SINK_LEN_THRD,the default action is sink and the sink session id is 31   */
     CTC_DTEL_INT_EXCEED_REP_LEN_ACTION,        /**< [TMM.AT] The INT Header's length exceed  CTC_DTEL_INT_REP_LEN_THRD,the default action is CTC_DTEL_INT_TRANSIT_ACTION_COPY_TO_CPU and sink, the sink session id is 31 */
     CTC_DTEL_INT_BELOW_REMAIN_HOP_ACTION,  /**< [TMM.AT] the INT PKT's Remaining Hop Cnt below CTC_DTEL_INT_REMAIN_HOP_THRESHOLD*/

    CTC_DTEL_TSX_CFG,       /**< [TMM.AT] telemetry statistics export config, refer to ctc_dtel_tsx_cfg_t */
    CTC_DTEL_TEX_CFG,       /**< [TMM.AT] telemetry events export config, refer to ctc_dtel_tex_cfg_t */
    CTC_DTEL_TIX_CFG,       /**< [TMM.AT] telemetry informations export config, refer to ctc_dtel_tix_cfg_t */

    CTC_DTEL_IFA_EN,        /**< [TMM.AT] Enable IFA */
    CTC_DTEL_IFA_PROTOCOL,  /**< [TMM.AT] IFA protocol, default value is 253*/
    CTC_DTEL_SWITCH_ID,     /**< [TMM.AT] Switch ID */
    CTC_DTEL_INT_MODE_CFG,   /**< [TMM.AT] INT mode config, refer to ctc_dtel_int_mode_cfg_t */
    CTC_DTEL_INT_TUNNEL_DEFAULT_SESSION_ID, /**< [TMM.AT] INT over tunnel decap used default session ID to report INT packet */
    CTC_DTEL_IFA_MODE_CFG    /**< [AT] INT mode config, refer to ctc_dtel_ifa_mode_cfg_t */
};
typedef enum ctc_dtel_property_e ctc_dtel_property_t;

enum ctc_dtel_int_rep_bmp_e
{
    CTC_DTEL_INT_REP_LV1_PORT       = 1U << 0,  /**< [TMM.AT] Level 1 Ingress port ID + Egress port ID*/
    CTC_DTEL_INT_REP_HOP_LATENCY    = 1U << 1,  /**< [TMM.AT] Hop latency*/
    CTC_DTEL_INT_REP_QUEUE_INFO     = 1U << 2,  /**< [TMM.AT] Queue id + Queue occupancy*/
    CTC_DTEL_INT_REP_EGR_TS         = 1U << 3,  /**< [TMM.AT] Egress timestamp*/
    CTC_DTEL_INT_REP_EPTU           = 1U << 5   /**< [TMM.AT] Egress port Tx utilization*/
};
typedef enum ctc_dtel_int_rep_bmp_e ctc_dtel_int_rep_bmp_t;

struct ctc_dtel_int_cfg_s
{
    uint8  session_id;          /**< [TMM.AT] INT Sink Session ID */

    uint8  log_en;              /**< [TMM.AT] Enable log */
    uint8  log_percent;         /**< [TMM.AT] Random log percent,refer to ctc_log_percent_t */
    uint8  postcard_en;         /**< [TMM.AT] Enable postcard mode */
    uint8  rep_md_bits;         /**< [TMM.AT] Report metadata bitmap, refer to ctc_dtel_int_rep_bmp_t */
    uint8  log_id;              /**< [TMM.AT] Log id */
    uint32 nh_id;               /**< [TMM.AT] Report destination */
};
typedef struct ctc_dtel_int_cfg_s ctc_dtel_int_cfg_t;

/**
 @brief  define Telemetry Statistics eXport Type
*/
enum ctc_dtel_tsx_type_e
{
    CTC_DTEL_TSX_MAC_STATS,         /**< [TMM.AT] tsx type mac stats */
    CTC_DTEL_TSX_DROP_STATS,        /**< [TMM.AT] tsx type drop stats */
    CTC_DTEL_TSX_BUFFER_WATERMARK,  /**< [TMM.AT] tsx type buffer watermark */
    CTC_DTEL_TSX_LATENCY_WATERMARK, /**< [TMM.AT] tsx type latency watermark */
    CTC_DTEL_TSX_BUFFER_STATS,      /**< [TMM.AT] tsx type buffer stats */
    CTC_DTEL_TSX_LATENCY_STATS,     /**< [TMM.AT] tsx type latency stats */
    CTC_DTEL_TSX_TYPE_MAX
};
typedef enum ctc_dtel_tsx_type_e ctc_dtel_tsx_type_t;

struct ctc_dtel_tsx_cfg_s
{
    uint32 type;                /**< [TMM.AT] tsx type, refer to ctc_dtel_tsx_type_t */
    uint8  enable;              /**< [TMM.AT] enable or disable tsx functions according to the type. */
    ctc_port_bitmap_t port_bmp; /**< [TMM.AT] config port bitmap to enable tsx */
    uint32 interval;            /**< [TMM.AT] export interval,  units: ms */
    uint32 nh_id;               /**< [TMM.AT] nexthop id, post the export destination and header info. 0 means disable */
};
typedef struct ctc_dtel_tsx_cfg_s ctc_dtel_tsx_cfg_t;

/**
 @brief  define Telemetry Events eXport Type
*/
enum ctc_dtel_tex_type_e
{
    CTC_DTEL_TEX_DROP_EVENT,        /**< [TMM.AT] tex type packet drop event */
    CTC_DTEL_TEX_BUFFER_EVENT,      /**< [TMM.AT] tex type buffer event */
    CTC_DTEL_TEX_LATENCY_EVENT,     /**< [TMM.AT] tex type latency event */
    CTC_DTEL_TEX_TYPE_MAX
};
typedef enum ctc_dtel_tex_type_e ctc_dtel_tex_type_t;

struct ctc_dtel_tex_cfg_s
{
    uint32 type;           /**< [TMM.AT] tex type, refer to ctc_dtel_tex_type_t */
    uint32 nh_id;          /**< [TMM.AT] nexthop id, post the export destination and header info. 0 means disable */
};
typedef struct ctc_dtel_tex_cfg_s ctc_dtel_tex_cfg_t;

/**
 @brief  define Telemetry Informations eXport Type
*/
enum ctc_dtel_tix_type_e
{
    CTC_DTEL_TIX_IPFIX,             /**< [TMM.AT] tix type ipfix */

    CTC_DTEL_TIX_TYPE_MAX
};
typedef enum ctc_dtel_tix_type_e ctc_dtel_tix_type_t;

struct ctc_dtel_tix_cfg_s
{
    uint32 type;           /**< [TMM.AT] tix type, refer to ctc_dtel_tix_type_t */
    uint32 nh_id;          /**< [TMM.AT] nexthop id, post the export destination and header info. 0 means disable */
    uint8 eunit_en;        /**< [TMM.AT] 1, to ecpu; 0, to cpu */
};
typedef struct ctc_dtel_tix_cfg_s ctc_dtel_tix_cfg_t;

struct ctc_dtel_global_cfg_s
{
    uint8 ifa_eunit_en;     /**< [TMM.AT] if enabled, indicates ifa works on eunit.*/
};
typedef struct ctc_dtel_global_cfg_s ctc_dtel_global_cfg_t;

/**@} end of @defgroup dtel DTEL */


#ifdef __cplusplus
}
#endif

#endif  /*_CTC_DTEL_H*/


